<script>
	import {
		mapMutations
	} from 'vuex'
	import myCloud from '@/common/util/cloud.js'
	import myConst from '@/common/util/const.js'
	import { wxLogin,getUserInfo,updateUser } from '@/common/api/user.js'
	export default {
		onLaunch: function() {
			let userId = uni.getStorageSync('userId')
			if (userId) {
				let tmpA = {
					mobile: uni.getStorageSync("userName"),
					uid:uni.getStorageSync("userId"),
					token:uni.getStorageSync("uniIdToken")
				}
				this.login(tmpA)
			}else{
				this.oauth('weixin')
			}
			let userInfo = uni.getStorageSync('userInfo')
			if (userInfo) {
				this.setUserInfo(uni.getStorageSync("userInfo"))
			}
			// const data = {
			// 	uid: uni.getStorageSync('userId'),
			// 	last_login_date: new Date().getTime()
			// }
			// updateUser(data).then(res=>{
				
			// })
			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			...mapMutations(['login','setUserInfo']),
			oauth(v) {
				var that = this;
				uni.login({
					provider: v,
					success: function(loginRes) {
						console.log(loginRes)
						const data = {
							code: loginRes.code
						}
						wxLogin(data).then(res=>{
							console.log(res)
							that.$api.msg(res.msg);
							if (res.code == 0) {
								const data2 = {
									uid: res.uid,
									field: ['mobile']
								}
								getUserInfo(data2).then(res2=>{
									if (res2.code == 0) {
										if (res2.userInfo.mobile == undefined) {
											res.mobile = ''
										} else {
											res.mobile = res2.userInfo.mobile
										}
										uni.setStorageSync('userId', res.uid)
										uni.setStorageSync("userName",res.mobile);
										uni.setStorageSync('uniIdToken', res.token)
										uni.setStorageSync('uni_id_token_expired', res.tokenExpired)
										that.login(res)
									}
								})
							}
						})
					}
				});
			}
		}
	}
</script>

<style lang='scss'>
	/*每个页面公共css */
	@import './common/style/uni.css';
	@font-face {
	  font-family: 'iconfont';  /* project id 1770871 */
	  src: url('//at.alicdn.com/t/font_1770871_uybpv5slfv.eot');
	  src: url('//at.alicdn.com/t/font_1770871_uybpv5slfv.eot?#iefix') format('embedded-opentype'),
	  url('//at.alicdn.com/t/font_1770871_uybpv5slfv.woff2') format('woff2'),
	  url('//at.alicdn.com/t/font_1770871_uybpv5slfv.woff') format('woff'),
	  url('//at.alicdn.com/t/font_1770871_uybpv5slfv.ttf') format('truetype'),
	  url('//at.alicdn.com/t/font_1770871_uybpv5slfv.svg#iconfont') format('svg');
	}
	@font-face {
		font-family: yticon;
		font-weight: normal;
		font-style: normal;
		src: url('https://at.alicdn.com/t/font_1078604_w4kpxh0rafi.ttf') format('truetype');	
	}
	page{
		background-color: $zx-page-background-color;
	}
	.icon{
		font-size: 24px;
		font-family: iconfont;
		color: rgb(255, 68, 68);
	}
	.yticon {
		font-family: "yticon" !important;
		font-size: 16px;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}
	.icon-shouye:before {
		content: "\e626";
	}
	.icon-daifukuan:before {
		content: "\e68f";
	}
	.icon-yishouhuo:before {
		content: "\e71a";
	}
	.icon-shouhoutuikuan:before {
		content: "\e631";
	}
	.icon-lishijilu:before {
		content: "\e6b9";
	}
	.icon-iconfontweixin:before {
		content: "\e611";
	}
	.icon-dizhi:before {
		content: "\e614";
	}
	.icon-share:before {
		content: "\e656";
	}
	.icon-pinglun-copy:before {
		content: "\e612";
	}
	.icon-shoucang_xuanzhongzhuangtai:before {
		content: "\e6a9";
	}
	.icon-shezhi1:before {
		content: "\e61d";
	} 
	.icon-you:before {
		content: "\e606";
	}
	.icon-jia2:before {
		content: "\e60a";
	}
	.icon--jianhao:before {
		content: "\e60b";
	}
	.icon-fork:before {
		content: "\e61b";
	}
	.icon-xuanzhong2:before {
		content: "\e62f";
	}
	.icon-zuojiantou-up:before {
		content: "\e605";
	}
	.icon-weixinzhifu:before {
		content: "\e61a";
	}
	.icon-alipay:before {
		content: "\e636";
	}
	.icon-erjiye-yucunkuan:before {
		content: "\e623";
	}
	.icon-iconfontshanchu1:before {
		content: "\e619";
	}
	.icon-fenlei1:before {
		content: "\e620";
	}
	.icon-shouhuodizhi:before {
		content: "\e712";
	}
	
	/*边框*/
	.b-b:after,
	.b-t:after {
		position: absolute;
		z-index: 3;
		left: 0;
		right: 0;
		height: 0;
		content: '';
		transform: scaleY(.5);
		border-bottom: 1px solid $border-color-base;
	}  
	 
	.b-b:after {
		bottom: 0;
	}
	
	.b-t:after {
		top: 0;
	}
</style>
